<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>


<html>
<head>
    <title>添加视频信息</title>
    <%@ include file="../../common/base.jsp" %>

    <script type="text/javascript">

        function addSubmit() {
            if (!validateContentNotNull('title',1,60,'视频标题',true)) {
                return false;
            }
            $.ajax({
                type: "POST",
                url: "${pageContext.request.contextPath}/video/saveVideo",
                dataType: "json",
                data: getParams(),
                success: function (data) {
                    if (data.errorCode == 0) {
                        prompt.alert("添加视频成功！");

                        setTimeout(function () {
                            window.location.href = "${pageContext.request.contextPath}/video/showVideo";
                        }, 2000);
                    } else {
                        prompt.alert(data.msg);
                    }
                }
            });
        }

        //获取form表单所有参数
        function getParams() {
            var json = {};
            var title = $("#title").val();
            json["title"] = title;
            var imageUrl = $("#imageUrl").val();
            json["videoImageUrl"] = imageUrl;
            var videoUrl = $("#videoUrl").val();
            json["videoUrl"] = videoUrl;
            var content = $("#content").val();
            json["content"] = content;
            return json;
        }

        function fileVideoImageChange(txt){
            $.ajaxFileUpload({
                //需要链接到服务器地址
                url:"video/saveVideoImageFile",
                secureuri:false,
                fileElementId:"videoImageFile",           //文件选择框的id属性
                dataType: 'json',                             //返回值类型 一般设置为json
                success: function(data, status){
                    var obj = eval(data);
                    if(obj.errorCode == 0){
                        var fileName = obj.fileName;
                        $("#imageUrl").val(fileName);
                        prompt.alert("上传成功");
                        $("#a_value_1").text(txt);
                    }else{
                        prompt.alert("上传失败");
                    }
                },error: function (data, status, e){
                    prompt.alert("文件上传错误");
                }
            });
        }

        function fileVideoChange(txt){
            $.ajaxFileUpload({
                //需要链接到服务器地址
                url:"video/saveVideoFile",
                secureuri:false,
                fileElementId:"videoFile",           //文件选择框的id属性
                dataType: 'json',                             //返回值类型 一般设置为json
                success: function(data, status){
                    var obj = eval(data);
                    if(obj.errorCode == 0){
                        var fileName = obj.fileName;
                        $("#videoUrl").val(fileName);
                        prompt.alert("上传成功");
                        $("#a_value_2").text(txt);
                    }else{
                        prompt.alert("上传失败");
                    }
                },error: function (data, status, e){
                    prompt.alert("文件上传错误");
                }
            });

        }

    </script>

</head>

<body id="body">
<!--head-->
<div id="head">
    <jsp:include page="../../common/head.jsp"></jsp:include>
</div>
<!--head end-->
<!--container-->
<div id="container">
    <div id="pageId" style="display: none;">05-07-03</div>
    <!--sidebar-->
    <%@ include file="../../common/menu.jsp" %>
    <!--sidebar-->
    <!--main-->
    <div class="main" id="mainDiv">
        <div class="channel_manage">
            <div class="location" style="background-position:22px -29px;">
                平台管理<span>&gt;</span>APP首页配置<span>&gt;</span>视频管理<span>&gt;</span>添加视频
            </div>
            <form method="post" enctype="multipart/form-data">
                <!--content-->
                <div class="content">
                    <div class="inputInfoList3">
                        <ul class="recharge_list" style="width:600;">
                            <li>
                                <label>视频标题</label>
                                <input type="text" id="title" name="title"
                                       onFocus="this.style.border = '1px solid #2A7CCF'"
                                       onblur="validateContentNotNull('title',1,60,'视频标题');this.style.border = '1px solid #D5D5D5'"/>
                                <span style="position:absolute;left:76%;top:9px;color:red;" class="red">*</span>
                                <i style="display: none;background-position: left center;" id="titles" class="s_tips"></i>
                                <i style="display: none;background-position: left center;padding-left:28%;" id="titleZhu" class="zhu_shi_2"></i>
                            </li>
                            <li>
                                <label>视频封面图</label>
                                <div class="file" style="width: 280px;">
                                    <input type="hidden" id="imageUrl" name="imageUrl" >
                                    <input type="file" id="videoImageFile" name="videoImageFile" onChange="fileVideoImageChange(this.value)" >
                                    <span id="a_value_1">选择视频封面图片文件上传</span>
                                </div>
                            </li>
                            <li>
                                <label>视频文件</label>
                                <div class="file" style="width: 280px;">
                                    <input type="hidden" id="videoUrl" name="videoUrl" >
                                    <input type="file" id="videoFile" name="videoFile" onChange="fileVideoChange(this.value)" >
                                    <span id="a_value_2">选择视频文件上传</span>
                                </div>
                            </li>
                            <li>
                                <label>视频描述</label>
                                <textarea id="content" name="content" rows="8" style="width: 310px;"></textarea>
                            </li>
                        </ul>
                        <div class="button_wrap">
                            <a href="javascript:void(0);" onClick="addSubmit();" class="bg_green">完成</a>
                            <input type="reset" value="重置">
                        </div>
                    </div>
                </div>
                <!--content-->
            </form>
            <!--foot-->
            <%@ include file="../../common/foot.jsp" %>
            <!--foot-->
        </div>
    </div>
    <!--main-->
</div>
<script src="${pageContext.request.contextPath}/static/js/basic.js"></script>

</body>
</html>
